from api5 import *


#列出课程

coureListBefore = list_course()['retlist']

from datetime import datetime
curtime = datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
name='python'+curtime

retobj = add_course(name,'python语言','2')

assert  retobj['retcode'] == 0

if retobj['retcode'] == 0:
    print('添加课程成功')
else:
    raise Exception('添加课程失败')


#添加课程后列出课程
aftercourse=list_course()['retlist']

# createCount = len(aftercourse) - len(coureListBefore)
# assert createCount == 1

course = []
for one in aftercourse:
    if one not in coureListBefore:
        course.append(one)

#添加的新元素（one）长度为1
assert len(course)==1
#取出第一个元素
newcourse=course[0]


assert newcourse['name']==name
assert newcourse['desc']=='python语言'
assert newcourse['display_idx']== 2


# 清除环境操作
delete_course(newcourse['id'])

print('\n========= test case pass =============')
